# encoding:utf-8
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import models
from DjangoUeditor.models import UEditorField


class Image(models.Model):
    '''
    用户公共图片库
    '''
    img = models.FileField(upload_to='user/image/')
    descr = models.CharField(max_length=200)

# Create your models here.
class UserProfile(models.Model):
    '''
    用户扩展信息表
    '''
    user = models.OneToOneField(User)
    avatar = models.FileField('Label',upload_to='user/avatar/')
    name   = models.CharField(max_length=100)
    age    = models.CharField(max_length=10)
    telphone = models.CharField(max_length=100)
    address  = models.CharField(max_length=200)
    website  = models.CharField(max_length=200)
    birthday = models.CharField(max_length=200)
    gender   = models.CharField(max_length=50)
    QQ = models.CharField('QQ', max_length=50, blank=True, null=True)
    MSN = models.CharField(max_length=50, blank=True, null=True)
    IM = models.CharField(max_length=50, blank=True, null=True)
    position = models.CharField(u'目前所在地', max_length=200, blank=True, null=True)
    country = models.CharField(u'目前所在国家', max_length=50, blank=True, null=True, default=u'中国')

    def  create_user_profile(sender,instance,created,**kwargs):
        if created:
            UserProfile.objects.create(user = instance)

    post_save.connect(create_user_profile,sender=User)

class Article(models.Model):
    '''
    发表文章的model
    '''
    content = models.CharField(max_length=500)
    title   = models.CharField(max_length=100)
    pub_date  = models.DateTimeField(u'发表时间',auto_now_add=True, editable = True)
    update_date = models.DateTimeField(u'更新时间',auto_now=True,null=True)
    author  = models.ForeignKey(UserProfile,related_name='article')

class Question(models.Model):
    '''
    问题model
    '''
    title = models.CharField(max_length=200)
    # content = models.CharField(max_length=300)
    content=UEditorField(u'内容   ',height=100,width=500,default='test',imagePath="uploadimg/",filePath='upload',blank=True)
    c_time  = models.DateTimeField(u'创建时间',auto_now_add=True, editable = True)
    u_time  = models.DateTimeField(u'更新时间',auto_now=True,null=True)
    questioner   = models.ForeignKey(UserProfile,related_name='question')

class Ask(models.Model):
    '''
    回答model
    '''
    content = models.CharField(max_length=300)
    question = models.ForeignKey(Question,related_name='question')
    asker    = models.OneToOneField(UserProfile,unique=True)


class Tag(models.Model):
    '''
    标签／／暂时不用
    '''
    title = models.CharField(max_length=200)
    descr = models.CharField(max_length=300)

# class PostMan(models.Model):
#     sender = models.CharField(max_length=100)
#     content = models.CharField(max_length=500)
#


class Classmate(models.Model):
    '''
    同学录的创建
    '''
    user = models.ForeignKey(UserProfile,related_name='classmates')
    pic  = models.ForeignKey(Image,related_name='classs')
    content = models.CharField(max_length=500)
    classname = models.CharField(max_length=200)
    school    = models.CharField(max_length=50)




